package com.lechi.web.controller;


import com.lechi.web.common.core.controller.BaseController;
import com.lechi.web.common.core.domain.AjaxResult;
import com.lechi.web.common.core.page.TableDataInfo;
import com.lechi.web.system.domain.IotGreenhouseBo;
import com.lechi.web.system.service.IIotGreenhouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 大棚Controller
 *
 * @author yangguang
 * @date 2025-07-21
 */
@RestController
@RequestMapping("/iot/greenhouse")
public class IotGreenhouseController extends BaseController {

    @Autowired
    private IIotGreenhouseService iotGreenhouseService;

    /**
     * 查询大棚列表
     */
    @GetMapping("/list")
    public TableDataInfo list(IotGreenhouseBo iotGreenhouse) {
        startPage();
        List<IotGreenhouseBo> list = iotGreenhouseService.selectIotGreenhouseList(iotGreenhouse);
        return getDataTable(list);
    }

    /**
     * 获取大棚详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(iotGreenhouseService.selectIotGreenhouseById(id));
    }

    /**
     * 新增大棚
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody IotGreenhouseBo iotGreenhouse) {
        return toAjax(iotGreenhouseService.insertIotGreenhouse(iotGreenhouse));
    }

    /**
     * 修改大棚
     */
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody IotGreenhouseBo iotGreenhouse) {
        return toAjax(iotGreenhouseService.updateIotGreenhouse(iotGreenhouse));
    }

    /**
     * 删除大棚
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iotGreenhouseService.deleteIotGreenhouseByIds(ids));
    }
}
